home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 295_01 / bsetbuf.c < prev    next >
Text File  |  1989-12-28  |  2KB  |  69 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "bsetbuf.c    1.2 - 89/10/31" */
  5.  
  6. #include <errno.h>
  7. /*#include <stddef.h>*/
  8. #include "blkio_.h"
  9.  
  10. /*man---------------------------------------------------------------------------
  11. NAME
  12.      bsetbuf - assign buffering to a block file
  13.  
  14. SYNOPSIS
  15.      #include <blkio.h>
  16.  
  17.      int bsetbuf(bp, buf)
  18.      BLKFILE *bp;
  19.      void *buf;
  20.  
  21. DESCRIPTION
  22.      The bsetbuf function causes the storage area pointed to by buf to
  23.      be used by the block file associated with BLKFILE pointer bp
  24.      instead of an automatically allocated buffer area.  If buf is the
  25.      NULL pointer, bp will be completely unbuffered.  Otherwise, it
  26.      must point to a storage area of size no less than
  27.  
  28.           header size + block size * buffer count
  29.  
  30.      bsetbuf may be called at any time after opening the block file,
  31.      before and after it is read or written; the buffers are flushed
  32.      before installing the new buffer area.
  33.  
  34.      bsetbuf will fail if one or more of the following is true:
  35.  
  36.      [EINVAL]       bp is not a valid BLKFILE pointer.
  37.      [BENBUF]       bp is unbuffered and buf is not the NULL
  38.                     pointer.
  39.      [BENOPEN]      bp is not open.
  40.  
  41. SEE ALSO
  42.      bopen, bsetvbuf.
  43.  
  44. DIAGNOSTICS
  45.      Upon successful completion, a value of 0 is returned.  Otherwise,
  46.      a value of -1 is returned, and errno set to indicate the error.
  47.  
  48. ------------------------------------------------------------------------------*/
  49. int bsetbuf(bp, buf)
  50. BLKFILE *bp;
  51. void *buf;
  52. {
  53.     /* validate arguments */
  54.     if (!b_valid(bp)) {
  55.         errno = EINVAL;
  56.         return -1;
  57.     }
  58.     if ((bp->bufcnt == 0) && (buf != NULL)) {
  59.         errno = BENBUF;
  60.         return -1;
  61.     }
  62.  
  63.     if (buf == NULL) {
  64.         return bsetvbuf(bp, buf, bp->blksize, (size_t)0);
  65.     }
  66.  
  67.     return bsetvbuf(bp, buf, bp->blksize, bp->bufcnt);
  68. }
  69.